#include "window_common.h"
#include "gkt_face_id.h"

#if (defined(GKT_CONFIG_FACE_ID_ENABLE) && GKT_CONFIG_FACE_ID_ENABLE) \
	&& (defined(GKT_CONFIG_NETWORK_ENABLE) && GKT_CONFIG_NETWORK_ENABLE)

enum {
	WIDGET_ID_TITLE = 0,
	WIDGET_ID_SELECT,
	WIDGET_ID_HINT,
	WIDGET_ID_CANCEL_OK,
	WIDGET_ID_MAX
};

enum {
	TIMER_ID_TIMEOUT = 0,
	TIMER_ID_MAX
};

static const gkt_widget_select_attr_u sc_window_face_stranger_stay_time_widget_select_attr = {
	GKT_WIDGET_SELECT_NUMBER_ATTR(GKT_FACE_ID_STRANGER_STAY_TIME_MINTIME,
		GKT_FACE_ID_STRANGER_STAY_TIME_MAXTIME, 
		GKT_FACE_ID_STRANGER_STAY_TIME_STEP,
		GKT_FACE_ID_STRANGER_STAY_TIME_DEFAULT,
		WINDOW_TEXT_ID_MAX),
};

GKT_WINDOW_WIDGET_DESCS_DEFINE(face_stranger_stay_time) = {
	[WIDGET_ID_TITLE] = GKT_WIDGET_LABEL_DESC(
		GKT_WIDGET_F_ALIGN_MIDDLE | GKT_WIDGET_F_TITLE_MARK,
		WINDOW_FONT_NORMAL_SIZE,
		WINDOW_TITLE_FG_COLOR, WINDOW_TITLE_BG_COLOR,
		0, 0, 
		WINDOW_WIDGET_DEFAULT_WIDTH, WINDOW_WIDGET_NORMAL_HEIGHT,
		WINDOW_TEXT_ID_face_stranger_stay_time
	),
	[WIDGET_ID_SELECT] = GKT_WIDGET_SELECT_DESC(
		GKT_WIDGET_F_ALIGN_MIDDLE,
		WINDOW_FONT_LARGE_SIZE,
		WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR,
		0, WINDOW_WIDGET_NORMAL_HEIGHT, 
		WINDOW_WIDGET_DEFAULT_WIDTH, WINDOW_WIDGET_EXTRA_LARGE_HEIGHT,
		&sc_window_face_stranger_stay_time_widget_select_attr
	),
	[WIDGET_ID_CANCEL_OK] = GKT_WIDGET_LABEL_DESC(
		GKT_WIDGET_F_ALIGN_MIDDLE,
		WINDOW_FONT_NORMAL_SIZE, 
		WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR,
		0, WINDOW_WIDGET_NORMAL_HEIGHT * (WINDOW_NORMAL_ROWS - 1), 
		WINDOW_WIDGET_DEFAULT_WIDTH, WINDOW_WIDGET_NORMAL_HEIGHT,
		WINDOW_TEXT_ID_cancel_ok
	),
};

typedef struct _window_stranger_stay_time {
	uint32_t	stranger_stay_time;
} window_stranger_stay_time_s;
static window_stranger_stay_time_s s_window_stranger_stay_time;

static void window_face_stranger_stay_time_success(void)
{
	if(s_window_stranger_stay_time.stranger_stay_time != gp_window_data->face_stranger_stay_time) {
		gp_window_data->face_stranger_stay_time = s_window_stranger_stay_time.stranger_stay_time;
		window_data_save();
	}

	window_dialog_show_big_prompt(WINDOW_DIALOG_HINT_SUCCESS,
			WINDOW_TEXT_ID_face_stranger_stay_time,
			WINDOW_TEXT_ID_set_success,
			WINDOW_VOICE_COMBINED_ID(set_success));
	gkt_window_exit();
}

static int window_face_stranger_stay_time_event_handler(
				uint32_t major_type, uint32_t minor_type,
				uint32_t id, uint32_t data)
{
	gkt_info("face_stranger_stay_time: (%u)(%u-%d)\n",
		minor_type, id, (int32_t)data);

	switch (major_type) {
		case GKT_EVENT_WINDOW:
			if (minor_type == GKT_WINDOW_INIT) {
				s_window_stranger_stay_time.stranger_stay_time = gp_window_data->face_stranger_stay_time;
				if ((s_window_stranger_stay_time.stranger_stay_time < GKT_FACE_ID_STRANGER_STAY_TIME_MINTIME)
					|| (s_window_stranger_stay_time.stranger_stay_time > GKT_FACE_ID_STRANGER_STAY_TIME_MAXTIME))
				{
					s_window_stranger_stay_time.stranger_stay_time = GKT_FACE_ID_STRANGER_STAY_TIME_DEFAULT;
				}
			}
			else if (minor_type == GKT_WINDOW_ACTIVE) {
				window_common_mask_except_updn_cancel_ok();
				if (data) {
					gkt_widget_select_set_value(WIDGET_ID_SELECT,
						s_window_stranger_stay_time.stranger_stay_time);
				}
			}
			break;
		case GKT_EVENT_WIDGET:
			if (minor_type == GKT_WIDGET_EVENT_CLICK) {
				s_window_stranger_stay_time.stranger_stay_time = gkt_widget_select_get_value(WIDGET_ID_SELECT);
				window_face_stranger_stay_time_success();
				return GKT_EVENT_HANDLE_COMPLETE;
			}
			break;
		default:
			break;
	}

	return GKT_EVENT_HANDLE_CONTINUE;
}
GKT_WINDOW_DESC_DEFINE(face_stranger_stay_time);

#endif

